﻿using System;
using System.Net.Http.Headers;
namespace Dome13
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("********欢迎进入启动界面*********");


            if (true)
            {
                Console.WriteLine("********欢迎进入用户登录页面*********");
                Console.WriteLine("请输入用户名：");
                string userName = Console.ReadLine();
                Console.WriteLine("请输入密码：");
                string passWord = Console.ReadLine();
                string uN = "王大姐";
                string pW = "1234";
                int count = 2;
                while (true)
                {

                    if (userName == uN && passWord == pW)
                    {
                        Console.WriteLine("********恭喜您登录成功*********");
                        Console.WriteLine("******欢迎进入功能菜单栏*******");
                        Console.WriteLine("******1.学生成绩输入*******");
                        Console.WriteLine("******2.学生成绩输出*******");
                        Console.WriteLine("******3.学生成绩查询*******");
                        Console.WriteLine("******4.学生成绩修改*******");
                        Console.WriteLine("******0.退出系统***********");
                        break;

                    }
                    else
                    {
                        if (count > 0)
                        {
                            Console.WriteLine("您输入的用户名或密码错误，请重新输入");
                            Console.WriteLine("您还有{0}次机会哦！！！", count--);
                            Console.WriteLine("请输入用户名：");
                            userName = Console.ReadLine();
                            Console.WriteLine("请输入密码：");
                            passWord = Console.ReadLine();

                        }
                    }
                }
                Console.WriteLine("请输入要输入的学生数：");
                int N_S = int.Parse(Console.ReadLine());
                Console.WriteLine("******1.学生成绩输入*******");
                Console.WriteLine("******2.学生成绩输出*******");
                Console.WriteLine("******3.学生成绩查询*******");
                Console.WriteLine("******4.学生成绩修改*******");
                Console.WriteLine("******0.退出系统***********");
                string[,] student = new string[N_S, 7];
                int n = int.Parse(Console.ReadLine());
                while (true)
                {
                    switch (n)
                    {
                        case 1:
                            Console.WriteLine(" 1.学生成绩输入");
                            InputStudent(student, N_S);
                            break;
                        case 2:
                            Console.WriteLine(" 2.学生成绩输出");
                            OutStudent(student, N_S);
                            break;
                        case 3:
                            Console.WriteLine(" 3.学生成绩查询");
                            Console.WriteLine("请输入学号：");
                            string id = Console.ReadLine();
                            InquierStudent(student, id);
                            break;
                        case 4:
                            Console.WriteLine(" 4.学生成绩修改");
                            Console.WriteLine("学号固定不变，按照学号查找");
                            Console.WriteLine("请输入学号：");
                            string id1 = Console.ReadLine();
                            AmendStudent(student, id1);
                            break;
                        case 0:
                            Console.WriteLine(" 0.退出系统");
                            break;
                        default:
                            Console.WriteLine("您输入的数字有误，请重新输入(0~4)");
                            break;
                    }
                    Console.WriteLine();
                    Console.WriteLine("******欢迎进入功能菜单栏*******");
                    Console.WriteLine("******1.学生成绩输入*******");
                    Console.WriteLine("******2.学生成绩输出*******");
                    Console.WriteLine("******3.学生成绩查询*******");
                    Console.WriteLine("******4.学生成绩修改*******");
                    Console.WriteLine("******0.退出系统***********");
                    Console.WriteLine("请选择功能：");
                    n = int.Parse(Console.ReadLine());
                }

            }
        }

        private static void AmendStudent(string[,] student, string id1)
        {
            int i = 0;
            for (; i < student.Length; i++)
            {
                if (student[i, 0] == id1)
                {
                    Console.WriteLine("**************************该学生的信息**********************");
                    Console.WriteLine("|----------------------------------------------------------|");
                    Console.WriteLine("| 学号  | 姓名  |  语文 |  数学  | 英语  |  总分 | 平均分  |");
                    Console.WriteLine("|----------------------------------------------------------|");
                    Console.WriteLine("|{0,10} | {1,3} | {2,4} | {3,4}  | {4,4} | {5,5} | {6,6:F2}|", student[i, 0], student[i, 1], student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                    Console.WriteLine("|----------------------------------------------------------|");
                    Console.WriteLine();
                    int temp = 0;
                    Console.WriteLine("-------------------------");
                    Console.WriteLine("******1.修改姓名*********");
                    Console.WriteLine("******2.修改语文成绩*****");
                    Console.WriteLine("******3.修改数学成绩*****");
                    Console.WriteLine("******4.修改英语成绩*****");
                    Console.WriteLine("******0.退出修改*********");
                    Console.WriteLine("-------------------------");
                    Console.WriteLine("请输入要修改的选项（对应的序号）");
                    int j = int.Parse(Console.ReadLine());
                    while (j != 0)
                    {
                        switch (j)
                        {
                            case 1:
                                Console.WriteLine("请输入修改后的姓名：");
                                student[i, 1] = Console.ReadLine();
                                break;
                            case 2:
                                Console.WriteLine("请输入修改后的语文：");
                                student[i, 2] = Console.ReadLine();
                                break;
                            case 3:
                                Console.WriteLine("请输入修改后的数学：");
                                student[i, 3] = Console.ReadLine();
                                break;
                            case 4:
                                Console.WriteLine("请输入修改后的英语：");
                                student[i, 4] = Console.ReadLine();
                                break;
                            case 0:
                                Console.WriteLine("******0.退出修改*********");
                                break;
                            default:
                                Console.WriteLine("您输入的序号错误，请重新输入");
                                break;
                        }
                        Console.WriteLine("请输入要修改的选项（对应的序号1`4）");
                        j = int.Parse(Console.ReadLine());
                    }
                    temp = Convert.ToInt32(student[i, 2]) + Convert.ToInt32(student[i, 3]) + Convert.ToInt32(student[i, 4]);
                    student[i, 5] = Convert.ToString(temp);
                    //计算平均分
                    student[i, 6] = string.Format("{0:F2}", temp / 3.0);
                    Console.WriteLine("**********************修改侯该学生的信息***********************");
                    Console.WriteLine("|-------------------------------------------------------------|");
                    Console.WriteLine("| 学号  | 姓名  |  语文 |  数学  | 英语  | 总分  |    平均分  |");
                    Console.WriteLine("|-------------------------------------------------------------|");
                    Console.WriteLine("|{0,10} | {1,3} | {2,4} |  {3,4} | {4,4} | {5,5} |  {6,6:F2}  |", student[i, 0], student[i, 1], student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                    Console.WriteLine("|-------------------------------------------------------------|");
                    Console.WriteLine();
                    break;

                }
                if (i >= student.Length)
                {
                    Console.WriteLine("查找失败，您输入的学号有误！！！");
                }
                Console.ReadKey();
            }
        }

        private static void InquierStudent(string[,] student, string id)
        {
            int i = 0;
            for (; i < student.Length; i++)
            {
                if (student[i, 0] == id)
                {
                    Console.WriteLine("**********************该学生的信息***********************");
                    Console.WriteLine("|--------------------------------------------------------|");
                    Console.WriteLine("|  学号  | 姓名  | 语文 | 数学 | 英语 | 总分  |  平均分  |");
                    Console.WriteLine("|--------------------------------------------------------|");
                    Console.WriteLine("| {0,10} | {1,3} |{2,4}| {3,4} | {4,4} | {5,5}| {6,6:F2} |", student[i, 0], student[i, 1], student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                    Console.WriteLine("|--------------------------------------------------------|");
                    break;
                }
            }
            if (i >= student.Length)
            {
                Console.WriteLine("查询失败，您输入的学号有误！！！！");
            }
        }

        private static void OutStudent(string[,] student, int num)
        {
            Console.WriteLine();
            Console.WriteLine("**********************该学生的信息***************************");
            Console.WriteLine("|------------------------------------------------------------|");
            Console.WriteLine("|   学号  |  姓名  |  语文 |  数学 |  英语 |  总分  | 平均分 |");
            Console.WriteLine("|------------------------------------------------------------|");
            for (int i = 0; i < num; i++)
            {
                Console.WriteLine("| {0,10} | {1,3} | {2,4} | {3,4} | {4,4} | {5,5}|  {6,6:F2}  |", student[i, 0], student[i, 1], student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                Console.WriteLine("|------------------------------------------------------------|");
            }
        }

        private static void InputStudent(string[,] student, int num)
        {
            int temp;
            string strStudent;
            string[] strInof;
            Console.WriteLine("请输入学生信息（以·分隔开）：学号·姓名·语文·数学·英语");
            for (int i = 0; i < num; i++)
            {
                Console.WriteLine("请输入第{0}个学生的信息。", i + 1);
                strStudent = Console.ReadLine();
                strInof = strStudent.Split('·');
                for (int j = 0; j < strInof.Length; j++)
                {
                    student[i, j] = strInof[j];
                }
                Console.WriteLine();
                //计算总分
                temp = Convert.ToInt32(student[i, 2]) + Convert.ToInt32(student[i, 3]) + Convert.ToInt32(student[i, 4]);
                student[i, 5] = Convert.ToString(temp);
                //计算平均分
                student[i, 6] = string.Format("{0:F2}", temp / 3.0);
            }
        }
    }
}